package com.ruoyi.location.domain.quickreport.util;

import java.util.Random;

public class RandomStringUtil {

    // 定义包含大小写字母和数字的字符集
    private static final String CHARACTERS = "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789";

    // 随机数生成器
    private static final Random RANDOM = new Random();

    /**
     * 生成指定长度的随机字符串
     *
     * @param length 字符串长度
     * @return 随机字符串
     */
    public static String generateRandomString(int length) {
        if (length <= 0) {
            throw new IllegalArgumentException("Length must be greater than zero");
        }

        StringBuilder sb = new StringBuilder(length);
        for (int i = 0; i < length; i++) {
            int index = RANDOM.nextInt(CHARACTERS.length());
            sb.append(CHARACTERS.charAt(index));
        }
        return sb.toString();
    }

    public static void main(String[] args) {
        // 测试生成8位随机字符串
        String randomString = generateRandomString(8);
        System.out.println("Generated Random String: " + randomString);
    }
}
